package interviewQuestions;

/**
 * 最长公共子串
 * https://blog.csdn.net/yjltx1234csdn/article/details/90046362
 *
 * */

public class TheLongestSubstring {
    public static String solve(String str1, String str2){
        String min = null;
        String max = null;

        if(str1.length() > str2.length()){
            min = str1;
            max = str2;
        }else {
            min = str2;
            max = str1;
        }
        if(max.contains(min)){
            return min;
        }
        for (int i = 0; i < min.length(); i++) {
            for (int start = 0,end = min.length() - i; end <= min.length(); start++,end++) {
                String t = min.substring(start, end);
                if (max.contains(t)) {
                    return t;
                }
            }
        }
        return null;
    }
    // main
    public static void main(String[] args) {
        String s = solve("abhwwa", "hww");
        System.out.println(s);

    }
}
